home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Text / print / HPDJ870Src.lha / dospecial.c < prev    next >
C/C++ Source or Header  |  2004-05-16  |  10KB  |  289 lines

  1. /*
  2.  **************************************************************************
  3.  *
  4.  *       DoSpecial for HP_Deskjet_870C driver.
  5.  *       By PJ Hutchison 15/12/97
  6.  *
  7.  **************************************************************************
  8.  */
  9.  
  10. #include "global.h"
  11.  
  12. #define LPI             9    /* Position in init.. string from 0 - 7 */
  13. #define CPI             21
  14. #define CHARSET         32
  15. #define QUALITY         42
  16. #define ASPECT          47   /* Portrait or Landscape */
  17. #define TYPEFACE        52
  18. #define INIT_LEN        54
  19. #define LPP             10   /* Lines Per Page  */
  20. #define FORM_LEN        14
  21. #define LEFT_MARG       3
  22. #define RIGHT_MARG      10
  23. #define MARG_LEN        15
  24.  
  25. /* Version string */
  26.  
  27. const char __ver[39] = "$VER: HP_Deskjet_870C 40.23 (14.05.04)";
  28.  
  29. extern struct PrinterData *PD;
  30. extern struct PrinterExtendedData *PED;
  31.  
  32. /* Routine to handle complex Escape sequences */
  33.  
  34. int DoSpecial(UWORD *command, char outputBuffer[], BYTE *vline, BYTE *currentVMI, BYTE *crlfFlag, UBYTE Parms[])
  35. {      
  36.         static UWORD textlength, topmargin;
  37.         int x, y, j, papersize, lpi;
  38.  
  39.         static char initThisPrinter[INIT_LEN + 1] =
  40.                 "\033&l26A\033&l6D\033&d@\033(s0b10h0p0s12V\033(1E\033*v1S\033*o0M\033&l0O\033(s3T";
  41.                 
  42.                 /* 00-05 \033&l26A   = A4 Paper
  43.                    06-10 \033&l6D    = 6 Lines per inch (LPI)
  44.                    11-14 \033&d@     = Underline off
  45.                    15-19 \033(s0b    = Normal weight (Bold off)
  46.                    20-22      10h    = 10 chars per inch (CPI)
  47.                    23-24       0p    = Fixed spacing
  48.                    25-26       0s    = Upright style
  49.                    27-29      12V    = 12 points/inch
  50.                    30-33 \033(1E     = UK Char set (CHARSET)
  51.                    34-38 \033*v1S    = Black text
  52.                    39-43 \033*o0M    = Quality (QUALITY)
  53.                    44-48 \033&l0O    = Portrait (ASPECT)
  54.                    49-53 \033(s3T    = Typeface
  55.                 */
  56.         static char initForm[FORM_LEN + 1] = "\033&l000E\033&l000F";
  57.         static char initMarg[MARG_LEN + 1] = "\033&a000L\033&a000M\015";
  58.         static char initTMarg[] = "\033&l000E\033&l000F";
  59.        
  60.         static char ISOColorTable[11] = "0102116881";
  61.  
  62.         x = y = j = 0;
  63.  
  64.         if (*command == aRIN) {         /* Initialise command */
  65.                 while(x < INIT_LEN) {
  66.                         outputBuffer[x] = initThisPrinter[x];
  67.                         x++;
  68.                 }
  69.                 outputBuffer[x++] = '\015';
  70.                                
  71.                 lpi = 6;
  72.                 if (PD->pd_Preferences.PrintSpacing == EIGHT_LPI) {
  73.                         outputBuffer[LPI] = '8';
  74.                         lpi = 8;
  75.                 }
  76.  
  77.                 if (PD->pd_Preferences.PrintPitch == ELITE) {
  78.                         outputBuffer[CPI] = '2';
  79.                 }
  80.                 else if (PD->pd_Preferences.PrintPitch == FINE) {
  81.                         outputBuffer[CPI] = '5';
  82.                 }
  83.                 if (PD->pd_Preferences.PrintQuality == LETTER) {
  84.                         outputBuffer[QUALITY] = '1';
  85.                 }
  86.                 /* Change to Landscape (Vert)) if selected) */
  87.                 if (PD->pd_Preferences.PrintAspect == ASPECT_VERT) {
  88.                             outputBuffer[ASPECT] = '1';
  89.                 }
  90.  
  91.                 j = x; /* set the formlength = textlength, top margin = 1 */
  92.                 papersize = PD->pd_Preferences.PaperSize;
  93.         switch (papersize) 
  94.         {
  95.            case US_LETTER:
  96.             papersize = 10 * lpi;
  97.             break;
  98.            case US_LEGAL:
  99.             papersize = 13 * lpi;
  100.             break;
  101.            case EURO_A4:
  102.             papersize = (lpi == 8 ? 85 : 65);
  103.             break;
  104.            default:   /* Custom size */
  105.             papersize = PD->pd_Preferences.PaperLength;
  106.         }
  107.                 textlength = papersize;
  108.                 topmargin = 1;
  109.  
  110.                 while (y < FORM_LEN) {
  111.                         outputBuffer[x++] = initForm[y++];
  112.                 }
  113.                 numberString(textlength, j + LPP, outputBuffer);
  114.  
  115.                 Parms[0] = PD->pd_Preferences.PrintLeftMargin;
  116.                 Parms[1] = PD->pd_Preferences.PrintRightMargin;
  117.                 *command = aSLRM;
  118.         }
  119.  
  120.         if (*command == aSLRM) {        /* L&R Margins */
  121.                 j = x;
  122.                 y = 0;
  123.                 while(y < MARG_LEN) {
  124.                         outputBuffer[x++] = initMarg[y++];
  125.                 }
  126.                 numberString(Parms[0] - 1, j + LEFT_MARG, outputBuffer);
  127.                 numberString(Parms[1] - 1, j + RIGHT_MARG, outputBuffer);
  128.                 return(x);
  129.         }
  130.  
  131.         if ((*command == aSUS2) && (*vline == 0)) { /* Superscript on */
  132.                 *command = aPLU; /* Partial line up */
  133.                 *vline = 1;
  134.                 return(0);
  135.         }
  136.  
  137.         if ((*command == aSUS2) && (*vline < 0)) {
  138.                 *command = aRI; /* Reverse LF */
  139.                 *vline = 1;
  140.                 return(0);
  141.         }
  142.  
  143.         if ((*command == aSUS1) && (*vline > 0)) {  /* Superscript off */
  144.                 *command = aPLD; /* Partial line down */
  145.                 *vline = 0;
  146.                 return(0);
  147.         }
  148.  
  149.         if ((*command == aSUS4) && (*vline == 0)) { /* Subscript on */
  150.                 *command = aPLD;
  151.                 *vline = -1;
  152.                 return(0);
  153.         }
  154.  
  155.         if ((*command == aSUS4) && (*vline > 0)) {
  156.                 *command = aIND; /* Line feed */
  157.                 *vline = -1;
  158.                 return(0);
  159.         }
  160.  
  161.         if ((*command == aSUS3) && (*vline < 0)) { /* Subscript off */
  162.                 *command = aPLU;
  163.                 *vline = 0;
  164.                 return(0);
  165.         }
  166.  
  167.         if(*command == aSUS0) {              /* Normalise the line */
  168.                 if (*vline > 0) {
  169.                         *command = aPLD;
  170.                 }
  171.                 if (*vline < 0) {
  172.                         *command = aPLU;
  173.                 }
  174.                 *vline = 0;
  175.                 return(0);
  176.         }
  177.  
  178.         if (*command == aPLU) {
  179.                 (*vline)++;
  180.                 return(0);
  181.         }
  182.  
  183.         if (*command == aPLD){
  184.                 (*vline)--;
  185.                 return(0);
  186.         }
  187.  
  188.         if (*command == aSTBM) {        /* Top & bottom margins */
  189.                 if (Parms[0] == 0) {
  190.                         Parms[0] = topmargin;
  191.                 }
  192.                 else {
  193.                         topmargin = --Parms[0];
  194.                 }
  195.  
  196.                 if (Parms[1] == 0) {
  197.                         Parms[1] = textlength;
  198.                 }
  199.                 else {
  200.                         textlength=Parms[1];
  201.                 }
  202.                 while (x < 13) {
  203.                         outputBuffer[x] = initTMarg[x];
  204.                         x++;
  205.                 }
  206.                 numberString(Parms[0], 3, outputBuffer);
  207.                 numberString(Parms[1] - Parms[0], 10, outputBuffer);
  208.                 return(x);
  209.         }
  210.  
  211.         if (*command == aSLPP) {        /* Set form length */
  212.                 while(x < FORM_LEN) {
  213.                         outputBuffer[x] = initForm[x];
  214.                         x++;
  215.                 }
  216.                 /*restore textlength, margin*/
  217.                 numberString(topmargin, 3, outputBuffer);
  218.                 numberString(textlength, 10, outputBuffer);
  219.                 return(x);
  220.         }
  221.  
  222.         if (*command == aRIS) {         /* Reset */
  223.                 PD->pd_PWaitEnabled = 253;   /* Save data! */
  224.         }
  225.  
  226.         if (*command == aSFC) {               /* Foreground colour */
  227.                           if (Parms[0] == 39)
  228.                                    Parms[0] = 30;
  229.                           if (Parms[0] > 37)
  230.                                    return(0);
  231.                           outputBuffer[x++] = '\033';
  232.                           outputBuffer[x++] = '*';
  233.                           outputBuffer[x++] = 'v';
  234.                           outputBuffer[x++] = ISOColorTable[Parms[0]-30];
  235.                           if (Parms[0] == 34)
  236.                               outputBuffer[x++] = '2';
  237.                           if (Parms[0] == 35)
  238.                               outputBuffer[x++] = '0';
  239.                           outputBuffer[x++] = 'S';
  240.                           return(x);
  241.         }
  242.         return(0);
  243. }
  244.  
  245. /* Inserts Param into output buffer */
  246. void numberString(UBYTE Param, int x, char outputBuffer[])
  247. {
  248.         if (Param > 199) {
  249.                 outputBuffer[x++] = '2';
  250.                 Param -= 200;
  251.         }
  252.         else if (Param > 99) {
  253.                 outputBuffer[x++] = '1';
  254.                 Param -= 100;
  255.         }
  256.         else {
  257.                 outputBuffer[x++] = '0'; /* always return 3 digits */
  258.         }
  259.  
  260.         if (Param > 9) {
  261.                 outputBuffer[x++] = Param / 10 + '0';
  262.         }
  263.         else {
  264.                 outputBuffer[x++] = '0';
  265.         }
  266.  
  267.         outputBuffer[x] = Param % 10 + '0';
  268. }
  269.  
  270. int ConvFunc(char *buf, char c, int flag)
  271. /* expand lf into lf/cr flag (0-yes, else no ) */
  272. {
  273.         if (c == '\014') { /* if formfeed (page eject) */
  274.                 PED->ped_PrintMode = 0; /* no data to print */
  275.         }
  276.         return(-1); /* pass all chars back to the printer device */
  277. }
  278.  
  279. int Close(union printerIO *ior)
  280. {
  281.         if (PED->ped_PrintMode) { /* if data has been printed */
  282.                 (*(PD->pd_PWrite))("\014",1); /* eject page */
  283.                 (*(PD->pd_PBothReady))(); /* wait for it to finish */
  284.                 PED->ped_PrintMode = 0; /* no data to print */
  285.         }
  286.         return(0);
  287. }
  288.  
  289.